
<%@ page import="Answer" %>
<html>
  <head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="layout" content="main" />
  <g:set var="entityName" value="${message(code: 'answer.label', default: 'Answer')}" />
  <title><g:message code="default.list.label" args="[entityName]" /></title>
</head>
<body>
  <div class="nav">
	<span class="menuButton"><g:link class="list" action="stat">多选题统计结果</g:link></span>
	<span class="menuButton"><g:link class="list" action="bytext">问答题汇总</g:link></span>
  </div>
  <div class="body">
	<g:if test="${flash.message}">
	  <div class="message">${flash.message}</div>
	</g:if>
	<div class="list">
	  <g:each in="${answerInstanceList}" var="rsltUserAnswers">
		<g:set var="q" value="${Question.findById(rsltUserAnswers.key)}"/>
		<table>
		  <thead>
			<tr>
			  <th colspan="2">${q.id}. ${q.content}<br/>${q.questionItems}</th>
			</tr>
			<tr>
			  <th>部门</th>
			  <th>统计结果</th>
			</tr>
		  </thead>
		  <tbody>
		  <g:each in="${rsltUserAnswers.value}" status="j" var="rsltSubAnswers">
			<g:if test="${rsltSubAnswers.key != 'Total'}">
			  <tr class="${(j % 2) == 0 ? 'odd' : 'even'}">
				<td>${rsltSubAnswers.key}</td>
				<td>
				  <table>
					<tr>
					<g:each in="${1..q.multiSelect}" var="answerOrder">
					  <th>${answerOrder}</th>
					</g:each>
					</tr>
					<tr>
					<g:each in="${rsltSubAnswers.value}" var="rsltAnswerItems">
					  <td style="padding: 0px 0px">
						<table style="border:0px">
						  <g:set var="maxSelect" value="${0}"/>
						  <g:set var="answerItemId" value=""/>

						  <g:each in="${rsltAnswerItems.value}" var="answerItem">
							<g:if test="${answerItem.key !='totalOfDepartment'}">
							  <g:if test="${answerItem.value > maxSelect }">
								<g:set var="maxSelect" value="${answerItem.value}"/>
								<g:set var="answerItemId" value="${answerItem.key}"/>
							  </g:if>
							</g:if>
						  </g:each>
						  <tr><td style="padding: 1px 0px">${answerItemId}</td></tr>
						  <g:set var="totalOfDepartment" value="${rsltAnswerItems.value.get('totalOfDepartment')}"/>
						  <tr><td style="padding: 0px 1px">${maxSelect}/${totalOfDepartment} = ${(totalOfDepartment==0?0:maxSelect/totalOfDepartment)*100}%</td></tr>
						</table>
					  </td>
					</g:each>
					</tr>
					</table>
				  </td>
			  </tr>
			</g:if>
		  </g:each>
		  <g:each in="${rsltUserAnswers.value}" var="rsltSubAnswers">
			<g:if test="${rsltSubAnswers.key == 'Total'}">
			  
			  <tr class="even">
				<td>Total</td>
				<td>
				  <table>
					<tr>
					  <g:each in="${1..q.multiSelect}" var="answerOrder">
						<th>${answerOrder}</th>
					  </g:each>
					
					</tr>
					<tr>
					  <g:each in="${rsltSubAnswers.value}" var="rsltAnswerItems">
					  <td style="padding: 0px 0px">
						<table name="one_cell" style="border:0px">
						  <g:set var="maxSelect" value="${0}"/>
						  <g:set var="answerItemId" value=""/>
						  <g:each in="${rsltAnswerItems.value}" var="answerItem">
							<g:if test="${answerItem.key !='totalOfDepartment'}">
							  <g:if test="${answerItem.value > maxSelect }">
								<g:set var="maxSelect" value="${answerItem.value}"/>
								<g:set var="answerItemId" value="${answerItem.key}"/>
							  </g:if>
							</g:if>
						  </g:each>
						  <tr><td style="padding: 1px 0px">${answerItemId}</td></tr>
						  <g:set var="totalOfDepartment" value="${rsltAnswerItems.value.get('totalOfDepartment')}"/>
						  <tr><td style="padding: 0px 1px">${maxSelect}/${totalOfDepartment} = ${(totalOfDepartment==0?0:maxSelect/totalOfDepartment)*100}%</td></tr>
						</table>
					  </td>
					  </g:each>
					</tr>
					</table>
				  </td>
			  </tr>
			 </g:if>
			  </g:each>


		  </tbody>
		</table>
		<br/>
	  </g:each>
	</div>
  </div>
</body>
</html>
